package org.jmresler.fbi.nibrs.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class NibrsDataSourceConfiguration {

    @Bean
    @ConfigurationProperties("spring.datasource.nibrs")
    public DataSourceProperties nibrsDataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean
    public DataSource nibrsDataSource() {
        return nibrsDataSourceProperties()
                .initializeDataSourceBuilder()
                .build();
    }

    @Bean
    public JdbcTemplate nibrsJdbcTemplate(@Qualifier("nibrsDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
